#!/bin/sh
# (C) 2016-10-25 Yong-iL Joh
# License: MPLv2

export LANG=C
MYDIR=$(dirname "$0")
cur_dir=`pwd`

update_git() {
  _git=$1
  if [ -d ../${_git} ]; then
     cd ../${_git}
     _null=`git status >/dev/null 2>&1`
     _r=$?
     if [ $_r -eq 0 ]; then
        git checkout master >/dev/null 2>&1
        git pull            >/dev/null 2>&1
        cd ${cur_dir}
     else
        echo "fatal: Not a git repository"
        exit 2
     fi
  else
     echo "there is no such directory: $_git "
     exit 1
  fi
}

if [ ! -d ../poky ]; then
   echo "there is no poky layers on $PWD/.."
   exit 1
fi
update_git poky
$MYDIR/checkout_layer_hash.sh poky
update_git meta-openembedded
$MYDIR/checkout_layer_hash.sh meta-openembedded
if [ -d ../meta-gplv2 ]; then
update_git meta-gplv2
$MYDIR/checkout_layer_hash.sh meta-gplv2
fi
